Ext
		.define(
				'Inbox.view.inbox.FolderGrid',
				{
					extend : 'Ext.grid.Panel',
					alias : 'widget.folderGrid',

					initComponent : function() {
						this.addEvents('rowdblclick', 'select');

						Ext.apply(this, {
							cls : 'folder-grid',
							store : 'inbox.FolderItemStore',
							viewConfig : {
								itemId : 'view',
								plugind : [ {
									pluginId : 'preview',
									ptype : 'preview',
									bodyField : 'description',
									expanded : true
								} ],
								listeners : {
									scope : this,
									itemdblclick : this.onRowDblClick
								}
							},
							columns : [ {
								text : 'Title',
								dataIndex : 'title',
								flex : 1,
								renderer : this.formatTitle
							}, {
								text : 'Author',
								dataIndex : 'author',
								hidden : false,
								width : 200

							}, {
								text : 'Date',
								dataIndex : 'pubDate',
								renderer : this.formatDate,
								width : 200
							} ]
						});
						this.callParent(arguments);
						this.on('selectionchange', this.onSelect, this);
					},

					onRowDblClick : function(view, record, item, index, e) {
						this.fireEvent('rowdblclick', this, this.store
								.getAt(index));
					},

					onSelect : function(model, selections) {
						var selected = selections[0];
						if (selected) {
							this.fireEvent('select', this, selected);
						}
					},

					loadFolder : function(url) {
						/*var store = Ext.getStore('inbox.FolderItemStore');
						store.load();*/
					},

					onProxyException : function(proxy, response, operation) {
						Ext.Msg.alert("Error with data from server",
								operation.error);
						this.view.el.update('');

						// Update the detail view with a dummy empty record
						this.fireEvent('select', this, {
							data : {}
						});
					},

					formatTitle : function(value, p, record) {
						return Ext.String
								.format(
										'<div class="topic"><b>{0}</b></div>',
										value);
					},

					formatDate : function(date) {
						if (!date) {
							return '';
						}

						var now = new Date(), d = Ext.Date.clearTime(now, true), notime = Ext.Date
								.clearTime(date, true).getTime();

						if (notime === d.getTime()) {
							return 'Today ' + Ext.Date.format(date, 'g:i a');
						}

						d = Ext.Date.add(d, 'd', -6);
						if (d.getTime() <= notime) {
							return Ext.Date.format(date, 'D g:i a');
						}
						return Ext.Date.format(date, 'Y/m/d g:i a');
					}
				});